package com.mapbased.wfw.bind;

import com.mapbased.wfw.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class ComponentBinding
    extends AbstractBinding
{
    Component component;
    private java.lang.reflect.Method method;
    public ComponentBinding(String exp)
    {
        super(exp);
    }

    /**
     * getDirectValue
     *
     * @param context RenderContext
     * @return Object
     * @todo Implement this com.mapbased.wfw.bind.AbstractBinding method
     */
    protected Object getDirectValue(RenderContext context)
    {

        try
        {


            if(method == null)
            {
                synchronized(this)
                {

                    method=this.component.getClass().getMethod(this.
                        attributeName.trim() + "Binding",
                        new Class[]
                        {RenderContext.class});
                }
            }
            return method.invoke(component,new Object[]
                                 {context});
        }

        catch(Exception e)
        {
            throw new java.lang.RuntimeException(this.exp,e);
        }
    }

    public void setComponent(Component component)
    {
        this.component=component;
    }
}
